﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ValidationFramework
{
	public class MethodKey
	{
		/// <summary>
		/// Initializes a new instance of the MethodKey class.
		/// </summary>
		/// <param name="runtimeMethodHandle"></param>
		public MethodKey(RuntimeMethodHandle runtimeMethodHandle)
		{
			RuntimeMethodHandle = runtimeMethodHandle;
		}

		/// <summary>
		/// Initializes a new instance of the MethodKey class.
		/// </summary>
		public MethodKey(Delegate methodDelegate)
		{
			RuntimeMethodHandle = methodDelegate.Method.MethodHandle;
		}


		public RuntimeMethodHandle RuntimeMethodHandle { get; set; }

		// --- To support using as a dictionary key
		public override bool Equals(object obj)
		{
			var key = (MethodKey)obj;
			return this.RuntimeMethodHandle.Equals(key.RuntimeMethodHandle);
		}

		public override int GetHashCode()
		{
			//TODO: this is probably a poor hash algorithm. Its probably ok, but if we can come up with a better one replace this.
			return RuntimeMethodHandle.GetHashCode();
		}
	}
}
